def isPrime(q):
    if q == 1: return False
    t = True
    w = q - 1
    while w > 1:
        if not q % w:
            t = False
            break
        w -= 1
    return t

e = input ()
r =[]
for i in range(len(e)):
    for w in range(i + 1,len(e) +  1):
        q = int (e[i:w])
        if isPrime(q):
            r += [q]
print(max(r) if r else 0)
if q < 1000 or q > 10000:
    print("0")
